﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RATSharp.Model;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Windows.Data;
using RATSharpW7.Converters;

namespace RATSharpW7.ViewModel.CalendarViewModel
{
    /// <summary>
    /// Abstract ViewModel for single day i calendar, which is provided
    /// to View from ICalendarDataProvider. 
    /// Provides basic functionality and defines interface between View and ViewModel
    /// </summary>
    [DataContract]
    public abstract class AbstractDayViewModel : ReservationViewModel
    {

        [DataMember]
        public DateTime selectedDate { get; set; }
        
        public IDayViewColorProvider colorProvider { get; set; }

        public AbstractDayViewModel(DateTime selectedDate)
        {
            this.selectedDate = selectedDate;
        }

        public DateTime SelectedDate
        {
            get
            {
                return selectedDate;
            }
            set
            {
                selectedDate = value;
            }
        }

        public void loadPeriods()
        {
            Task<Reservations> task = getTask(selectedDate.Date, selectedDate.Date.AddDays(1).Add(new TimeSpan(0, -1, 0)));
            notifyChangeModel(task);
        }

        /// <summary>
        /// Provider do bind inco corresponding ColorConverter
        /// </summary>
        public IDayViewColorProvider ColorProvider
        {
            get
            {
                if (this.colorProvider == null)
                {
                    this.colorProvider = getColorProvider();
                }
                return this.colorProvider;
            }
        }

        /// <summary>
        /// return color provider to calendar
        /// </summary>
        /// <returns>color provider</returns>
        protected abstract IDayViewColorProvider getColorProvider();
        /// <summary>
        /// Define if user has right to edit reservation event
        /// </summary>
        /// <param name="period">event to edit</param>
        /// <returns>true if user can edit period</returns>
        public abstract bool isPeriodEditable(period period);

        /// <summary>
        /// get custom task for period loading
        /// </summary>
        /// <param name="firstDayInMonth">firstDayInMonth</param>
        /// <param name="LastDayInMonth">LastDayInMonth</param>
        /// <returns>async task</returns>
        protected abstract Task<Reservations> getTask(DateTime firstDayInMonth, DateTime LastDayInMonth);
    }
}
